home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / jaq / dist / jquery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-22  |  6.9 KB  |  275 lines

  1. /* 
  2.  * jquery.c --
  3.  *
  4.  *    Perform status query on Jaquith archive system.
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/jquery.c,v 1.0 91/01/07 18:02:37 mottsmth Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include "jaquith.h"
  21. #include "option.h"
  22.  
  23. static int    ProcessDevices  _ARGS_ ((int sock));
  24. static int    ProcessArchList _ARGS_ ((int sock));
  25.  
  26. static char printBuf[T_MAXSTRINGLEN];
  27.  
  28. static FILE *memDbg = NULL;   /* stream for memory tracing */
  29.  
  30. int jDebug;                   /* Internal debugging only */
  31. int syserr = 0;               /* Our personal record of errno */
  32.  
  33. #define DEF_SOCK -1 
  34. #define DEF_FLAGS -1
  35. #define DEF_DEBUG 0
  36. #define DEF_DISKLOW 70
  37. #define DEF_DISKHIGH 80
  38. #define DEF_USER ""
  39. #define DEF_GROUP ""
  40. #define DEF_HOST ""
  41. #define DEF_CLEANER ""
  42.  
  43. typedef struct parmTag {      /* Only really need a little of this ... */
  44.     int sock;
  45.     char *arch;
  46.     int flags;
  47.     char *root;
  48.     int debug;
  49.     int diskLow;
  50.     int diskHigh;
  51.     char *userName;
  52.     char *groupName;
  53.     char *hostName;
  54.     char *cleaner;
  55.     int fsyncFreq;
  56. } Parms;
  57.  
  58. Parms parms = {
  59.     DEF_SOCK,
  60.     DEF_ARCH,
  61.     DEF_FLAGS,
  62.     DEF_ROOT,
  63.     DEF_DEBUG,
  64.     DEF_DISKLOW,
  65.     DEF_DISKHIGH,
  66.     DEF_USER,
  67.     DEF_GROUP,
  68.     DEF_HOST,
  69.     DEF_CLEANER,
  70.     DEF_FSYNCFREQ
  71. };
  72.  
  73. Option optionArray[] = {
  74.     {OPT_INT, "socket", (char *)&parms.sock, "socket #"},
  75.     {OPT_STRING, "archive", (char *)&parms.arch, "archive name"},
  76.     {OPT_INT, "flags", (char *)&parms.flags, "option flags"},
  77.     {OPT_STRING, "root", (char *)&parms.root, "root of index tree"},
  78.     {OPT_TRUE, "debug", (char *)&parms.debug, "enable debugging output"},
  79.     {OPT_INT, "disklow", (char *)&parms.diskLow, "Low usable disk (%)"},
  80.     {OPT_INT, "diskhigh", (char *)&parms.diskHigh, "High usable disk (%)"},
  81.     {OPT_STRING, "username", (char *)&parms.userName, "Name of requestor"},
  82.     {OPT_STRING, "groupname", (char *)&parms.groupName, "Group name of requestor"},
  83.     {OPT_STRING, "hostname", (char *)&parms.hostName, "Machine name of requestor"},
  84.     {OPT_STRING, "cleaner", (char *)&parms.cleaner, "cleaning program"},
  85.     {OPT_INT, "fsyncfreq", (char *)&parms.fsyncFreq, "Do fsync every N files. Ignored."}
  86. };
  87. int numOptions = sizeof(optionArray) / sizeof(Option);
  88.  
  89.  
  90. /*
  91.  *----------------------------------------------------------------------
  92.  *
  93.  * jquery --
  94.  *
  95.  *    Main driver for status operations
  96.  *
  97.  * Results:
  98.  *    none.
  99.  *
  100.  * Side effects:
  101.  *    none.
  102.  *
  103.  * Note: jquery is invoked from the Jaquith switchboard process,
  104.  *       not from the command line.
  105.  *
  106.  *----------------------------------------------------------------------
  107.  */
  108.  
  109. int
  110. main(argc, argv)
  111.     int argc;                 /* See Option Array */
  112.     char *argv[];
  113. {
  114.     int sock;
  115.     int retCode;
  116.  
  117. /*    memDbg = fopen("jquery.mem","w"); */
  118.     MEM_CONTROL(8192, memDbg, TRACEMEM+TRACECALLS, 4096);
  119.  
  120.     argc = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  121.  
  122.     sock = parms.sock;
  123.     jDebug = parms.debug;
  124.  
  125.     ProcessDevices(sock);
  126.     ProcessArchList(sock);
  127.  
  128.     MEM_REPORT("jquery", ALLROUTINES, SORTBYOWNER);
  129.  
  130.     return T_SUCCESS;
  131. }
  132.  
  133.  
  134. /*
  135.  *----------------------------------------------------------------------
  136.  *
  137.  * ProcessDevices --
  138.  *
  139.  *    Call jukebox manager to get device status
  140.  *
  141.  * Results:
  142.  *    none.
  143.  *
  144.  * Side effects:
  145.  *    none.
  146.  *
  147.  *----------------------------------------------------------------------
  148.  */
  149.  
  150. static int
  151. ProcessDevices(sock) 
  152.     int sock;                 /* client socket */
  153. {
  154.     int status = -1;
  155.     int mgrSock;
  156.     int retCode = T_SUCCESS;
  157.     int count = -1;
  158.     int i;
  159.     int volId;
  160.     char devName[80];
  161.     char *devPtr = devName;
  162.     char hostName[80];
  163.     char *hostPtr = hostName;
  164.     char userName[80];
  165.     char *userPtr = userName;
  166.     char *archPath;
  167.     char *logPath;
  168.     ArchConfig archConfig;
  169.  
  170.     archPath = Str_Cat(3, parms.root, "/", parms.arch);
  171.     logPath = Str_Cat(3, archPath, "/", ARCHLOGFILE);
  172.  
  173.     if (Admin_ReadArchConfig(archPath, &archConfig) != T_SUCCESS) {
  174.     sprintf(printBuf,"Admin_ReadArchConfig failed: errno %d\n", syserr);
  175.     Log_AtomicEvent("jupdate", printBuf, logPath);
  176.     Sock_SendRespHdr(sock, T_ADMFAILED, syserr);
  177.     return -1;
  178.     }
  179.  
  180.  
  181.     if ((mgrSock=Sock_SetupSocket(archConfig.mgrPort,
  182.                   archConfig.mgrServer, 0))
  183.     != T_FAILURE) {
  184.     retCode = Sock_WriteString(mgrSock, parms.userName, 0);
  185.     retCode += Sock_WriteInteger(mgrSock, S_CMDSTAT);
  186.     retCode += Sock_WriteInteger(mgrSock, 0);
  187.     retCode += Sock_ReadInteger(mgrSock, &status);
  188.     if (retCode == T_SUCCESS) {
  189.         Sock_ReadInteger(mgrSock, &count);
  190.     }
  191.     }    
  192.  
  193.     Sock_WriteInteger(sock, count);
  194.  
  195.     for (i=0; i<count; i++) {
  196.     if ((Sock_ReadString(mgrSock, &devPtr, 0) != T_SUCCESS) ||
  197.         (Sock_ReadInteger(mgrSock, &volId) != T_SUCCESS) ||
  198.         (Sock_ReadString(mgrSock, &hostPtr, 0) != T_SUCCESS) ||
  199.         (Sock_ReadString(mgrSock, &userPtr, 0) != T_SUCCESS)) {
  200.         return(T_FAILURE);
  201.     }
  202.     if ((Sock_WriteString(sock, devPtr, 0) != T_SUCCESS) ||
  203.         (Sock_WriteInteger(sock, volId) != T_SUCCESS) ||
  204.         (Sock_WriteString(sock, hostPtr, 0) != T_SUCCESS) ||
  205.         (Sock_WriteString(sock, userPtr, 0) != T_SUCCESS)) {
  206.         return(T_FAILURE);
  207.     }
  208.     }
  209.  
  210.     if (count > -1) {
  211.     count = -1;
  212.     Sock_ReadInteger(mgrSock, &count);
  213.     }
  214.     Sock_WriteInteger(sock, count);
  215.  
  216.     for (i=0; i<count; i++) {
  217.     if ((Sock_ReadInteger(mgrSock, &volId) != T_SUCCESS) ||
  218.         (Sock_ReadString(mgrSock, &hostPtr, 0) != T_SUCCESS)||
  219.         (Sock_ReadString(mgrSock, &userPtr, 0) != T_SUCCESS)) {
  220.         return T_FAILURE;
  221.     }
  222.     if ((Sock_WriteInteger(sock, volId) != T_SUCCESS) ||
  223.         (Sock_WriteString(sock, hostPtr, 0) != T_SUCCESS)||
  224.         (Sock_WriteString(sock, userPtr, 0) != T_SUCCESS)) {
  225.         return T_FAILURE;
  226.     }
  227.     }
  228.  
  229.     close(mgrSock);
  230.  
  231.     return T_SUCCESS;
  232. }
  233.  
  234.  
  235. /*
  236.  *----------------------------------------------------------------------
  237.  *
  238.  * ProcessArchList --
  239.  *
  240.  *    Return list of logical archives to caller
  241.  *
  242.  * Results:
  243.  *    none.
  244.  *
  245.  * Side effects:
  246.  *    none.
  247.  *
  248.  *----------------------------------------------------------------------
  249.  */
  250.  
  251. static int
  252. ProcessArchList(sock) 
  253.     int sock;                 /* client socket */
  254. {
  255.     DIR *dirStream;
  256.     DirObject *entryPtr;
  257.     char *namePtr;
  258.  
  259.     if ((dirStream=opendir(parms.root)) != (DIR *)NULL) {
  260.     while ((entryPtr=readdir(dirStream)) != (DirObject *)NULL) {
  261.         if (Str_Match(entryPtr->d_name, "*.arch")) {
  262.         *(entryPtr->d_name+strlen(entryPtr->d_name)-5) = '\0';
  263.         Sock_WriteString(sock, entryPtr->d_name, 0);
  264.         }
  265.     }
  266.     closedir(dirStream);
  267.     }
  268.  
  269.     Sock_WriteString(sock, "", 0);
  270.  
  271.     return T_SUCCESS;
  272.  
  273. }
  274.  
  275.